<?php

namespace Wechat\Controller;

class IndexController extends CommonController  {

    /**
     * 引导页
     */
    public function index() {

//        if(isNullOrEmpty($this->customer["category_id"])) {
//            $this->redirect(U("userCenter/myInfo"));
//        }

        $category = D("Category")->queryById($this->customer["category_id"]);

        $map["p.category_id"] = $category["category_id"];

        $list = D("Product")->alias("p")
            ->join("left join __CATEGORY__ c on c.category_id = p.category_id")
            ->where($map)
            ->field("p.product_id,p.product_name,c.is_finished")
            ->select();

        foreach ($list as &$item) {
            $itemMap["pd.product_id"] = $item["product_id"];
            $item["desc_list"] = D("ProductDesc")->alias("pd")
                ->where($itemMap)
                ->select();

        }

        $categoryMap["category_id"] = $category["category_id"];
        $category["science_list"] = D("Science")
            ->where($categoryMap)
            ->select();

        $activityMap["a.category_id"] = $category["category_id"];
        $activityMap["a.status"] = array("in", array(
            C("ACTIVITY_STATUS.WAITING_JOIN"),
            C("ACTIVITY_STATUS.FULL")
        ));
        $activityList = D("Activity")->alias("a")
            ->where($activityMap)
            ->field("a.activity_id")
            ->select();

        $category["has_activity"] = !isNullOrEmpty($activityList);

        //employee job
//        $employee = D("Employee")->queryById($this->customer["customer_id"]);
//        $job = explode(',',$employee["job"]);
        $employee = D("Admin")->where(array('employee_id'=>$this->customer["customer_id"]))->find();
        $employeeRole = explode(',',$employee["role"]);
        $this->assign("employeeRole", $employeeRole);
        $this->assign("productList", $list);
        $this->assign("info", $this->customer);
        $this->assign("category", $category);
//        $this->assign("job", $job);
        $this->display("index");

    }

    public function test() {
        $this->assign("appId", C("appid"));
        $this->assign("config", $this->signature());
        $this->display("test");
    }

    public function bfo() {
        if (!check_role($this->customer["customer_id"], "1,2,3,4,5,6,7,8,9,10,11,12")) {
//            $this->error("您没有访问权限！");
            $this->redirect(U("userCenter/employeeInfo"));
        }

        //employee job
        $employee = D("Admin")->where(array('employee_id'=>$this->customer["customer_id"]))->find();

        $employeeRole = explode(',',$employee["role"]);

        $this->assign("employee", $employee);
        $this->assign("employeeRole", $employeeRole);
        $this->display("Index/bfo");

    }

}